import axios from 'axios'
import baseURL from './baseUrl'
import utils from '../utils/index'

axios.defaults.baseURL = baseURL
axios.defaults.withCredentials = true;
/* 响应拦截器 */
axios.interceptors.response.use(function (response) { 

    return response
}, function (error) {
    return error
})
// // 请求拦截器
axios.interceptors.request.use(function (request) {
    // 在发送请求之前做些什么 设置token 判断有没有token
    let token = utils.localStorage.get("token")
    if (token) {
        request.headers.token = `${token}`;
    }
    return request;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
export function get(url, params = {}) {
    return axios({
        method: 'get',
        url: url,
        params
    })
}

export function post(url, data) {
    return axios({
        method: 'post',
        url,
        data
    });
}


export function put(url, data) {
    return axios({
        method: 'put',
        url,
        data
    });
}

export function deletes(url, data) {
    return axios({
        method: 'delete',
        url,
        data: data
    });
}